package com.demolist.demo.list.v3;

import java.util.Arrays;

public class XinList {

    private String[] addarr;
    String[] elementData;


    public XinList() {
        String[] elementData ={};
    }

    public boolean add(String data ){
        int size=elementData.length+1;
        addarr=new String[size];
        addarr = Arrays.copyOf(elementData,size);
        addarr[elementData.length] = data;
        return true;
    }

    public boolean remove(String data ){
        int size=elementData.length;
        int position = 0;
        addarr=new String[size];
        for (int i = 0; i <elementData.length ; i++) {
            if (data.equals(elementData[i])){
                position = i;
            }else {
                addarr[i] = elementData[i];
            }
        }
        System.arraycopy(addarr,position+1,addarr,position,size-position-1);
        addarr = Arrays.copyOf(addarr,size-1);
        return true;
    }

    @Override
    public String toString() {
        return Arrays.toString(addarr);
    }
}
